Skip to content

Commit

Permalink
Grammar document update
Browse files Browse the repository at this point in the history
  • Loading branch information
Donn committed Oct 28, 2018
1 parent 9099129 commit b173430
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 96 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ phi
*.exe
*.stackdump

./*.phi
./*.phi
Examples/*.v
9 changes: 5 additions & 4 deletions Examples/d_ff.v
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Automatically generated by the Phi Compiler 0.0.1-dev (caef566)
Automatically generated by the Phi Compiler 0.0.1-dev (a8a7bc2)
Do not modify.
Generated on: 2018-10-28 10:58:56
Generated on: 2018-10-28 18:20:16
*/

module dFlipFlop(
Expand All @@ -11,8 +11,9 @@ module dFlipFlop(
input reset
);

wire [64'd31:64'd0] v=x;
reg [64'd31:64'd0] store;
always @ (posedge clock|negedge reset) begin // Cannot change to or as Verilog demands.
always @ (posedge clock|negedge reset) begin

if (reset) begin

Expand All @@ -22,6 +23,6 @@ end else begin
store <= a;
end
end
b = store; // Cannot add assign here due to noncontextual translation.
b = store;
endmodule

5 changes: 1 addition & 4 deletions Grammar/phi.yy
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,6 @@ statement:
| block_based {
$$ = $1;
}
| error ';' {
$$ = err_placeholder;
}
;

/* Blocks */
Expand Down Expand Up @@ -615,7 +612,7 @@ mux_block:
;
labeled_expression_list:
{ $$ = ε; }
| KEYWORD_CASE number ':' expression ';' labeled_expression_list {
| KEYWORD_CASE expression ':' expression ';' labeled_expression_list {
cst; stream << $2 << ": " << std::endl;
stream << "__PHI__MUX__LAST = " << $4 << ';' << std::endl;
stream << "break; " << std::endl;
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,6 @@ $(BINARY): $(OBJECTS) $(CPP_OBJECTS) $(CPP_LY_OBJECTS)
clean:
rm -rf $(BUILD_DIR)
rm -f $(BINARY)
rm -f Examples/*.v
rm -f ./*.phi
rm -f *.exe *.stackdump # MSYS2/Windows
10 changes: 4 additions & 6 deletions Specifications/1. Organization.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,18 @@ In Phi, it looks very similar, just with a different syntax:

```phi
module Counter(
clock: Clock,
reset: ResetAsyncLow,
clock: Input,
reset: @resetLow Input,
output: Output[31..0]
) {
Register[31..0] store = 32b0;
@ clock.posedge {
@ posedge clock {
store.next = store + 1;
}
out = store;
}
```

## Interfaces

## Namespaces
### TBC
5 changes: 1 addition & 4 deletions Specifications/A. Lexemes.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
* **Wire**
* **Register**

*annotation*:
* **@** *identifier*

*identifier*:
* *starter* *ender*

Expand Down Expand Up @@ -60,7 +57,7 @@
* **z** **x** *digit*

*digit*: any of
* **0 1 2 3 4 5 6 7 8 9**
* **0 1 2 3 4 5 6 7 8 9 A B C D E F**

*punctuator*: any of
* **@ $ ! ~ + - * < > / % | & ^ ? : ; , = . { } [ ] ( ) >= <= &+ &- &> &< &>= &<=**
176 changes: 103 additions & 73 deletions Specifications/B. Grammar.md
Original file line number Diff line number Diff line change
@@ -1,124 +1,151 @@
# Draft: Grammar

## Top Level

*description*:
* *declaration* *description*
* **namespace** *identifier* **{** *description* **}**
* ε

*declaration*:
* **module** *identifier* *template_declaration* **(** *port_declaration_list* **)** *inheritance* *block*
* **interface** *identifier* *template_declaration* **(** *port_declaration_list* **)** *inheritance* **;**
* **module** *identifier* *template-declaration* **(** *port-declaration-list* **)** *inheritance* *block*
* **interface** *identifier* *template-declaration* **(** *port-declaration-list* **)** *inheritance* **;**


*port_declaration_list*:
* *populated_port_declaration_list*
## Ports

*port-declaration-list*:
* *populated-port-declaration-list*
* ε

*populated_port_declaration_list*:
* *identifier* **:** *expression* **,** *populated_port_declaration_list*
*populated-port-declaration-list*:
* *identifier* **:** *expression* **,** *populated-port-declaration-list*
* *identifier* **:** *expression*

*port_declaration*:
* *port_polarity*
* *annotation* *port_polarity*
* **@resetLow** *port_polarity*
*port-declaration*:
* *port-polarity*
* **@** *identifier* *port-polarity*

*port_polarity*:
* **input** *optional_array_subscript*
* **output** *optional_array_subscript*
*port-polarity*:
* **Input** *optional-array-subscript*
* **Output** *optional-array-subscript*

*template_declaration*:
* **<** *template_declaration_list* **>**
## Templating
*template-declaration*:
* **<** *template-declaration-list* **>**

*template_declaration_list*:
* *identifier* *optional_template_assignment* *template_declaration_list*
* *identifier* *optional_template_assignment*
*template-declaration-list*:
* *identifier* *optional-template-assignment* *template-declaration-list*
* *identifier* *optional-template-assignment*

*optional_template_assignment*:
* **=** (*expression*)
*optional-template-assignment*:
* **=** **(** *expression* **)**
* ε


## Inheritance
*inheritance*:
* **:** *inheritance_list*
* **:** *inheritance-list*
* ε

*inheritance_list*:
* *lh_expression* **,** *inheritance_list*
* *lh_expression*

*block*:
* **{** statement_list **}**

*statement_list*:
* *statement_list* *statement*
* ε
*inheritance-list*:
* *lh-expression* **,** *inheritance-list*
* *lh-expression*

## Statements
*statement*:
* *subdeclaration* **;**
* *nondeclarative_statement* **;**
* *block_based*
* *nondeclarative-statement* **;**
* *block-based*

*block_based*:
*block-based*:
* *if*
* **for** *identifer* **in** *range* *block*
* **namespace** *identifier* *block*
* **switch** *expression* *switch-block*
* **@** *expression* *block*
* **async** *block*
* *if*

*if*:
* **if** *expression* *block* *else*

*else*:
* **else** *if*
* **else** *expression* *block*
* **else** *block*
* ε

*subdeclaration*:
* *subscriptable_dynamic_width* *declaration_list*
* *probable_template* *identifier* *ports*
*switch-block*:
* **{** *labeled-statement-list* **}**

*labeled-statement-list*:
* **case** *expression* **:** *statement_list* *labeled_statement_list*
* **default** *expression* **:** *statement_list*
* ε

*block*:
* **{** statement-list **}**

*statement-list*:
* *statement_list* *statement*
* ε

*subscriptable_dynamic_width*:
* *dynamic_width* *optional_array_subscript*
## Subdeclarations
*subdeclaration*:
* *dynamic-width* *optional-array-subscript* *declaration-list*
* *probable-template* *identifier* *ports*

*dynamic_width*:
*dynamic-width*:
* **Var**
* **Wire**
* **Register**

*declaration_list*:
* *identifier* *optional_array_subscript* *optional_assignment* **,** *declaration_list*
* *identifier* *optional_array_subscript* *optional_assignment*
*optional-array-subscript*:
* **[** *expression* **]**
* ε

*optional_assignment*:
*optional-ports*:
* *ports*
* ε

*declaration-list*:
* *identifier* *optional-array-subscript* *optional-assignment* **,** *declaration-list*
* *identifier* *optional-array-subscript* *optional-assignment*

*optional-assignment*:
* **=** *expression*
* ε

*probable_template*:
*probable-template*:
* *expression*
* *expression* **<** *template_list* **>**
* *expression* **<** *template-list* **>**

*template_list*:
* *identifier* **:** **(** *expression* **)** **,** *template_list*
*template-list*:
* *identifier* **:** **(** *expression* **)** **,** *template-list*
* *identifier* **:** **(** *expression* **)**
* ε

*ports*:
* **(** **)**
* **(** *port_list* **)**
* **(** *port-list* **)**

*port_list*:
* *identifier* **:** *expression* **,** *port_list*
*port-list*:
* *identifier* **:** *expression* **,** *port-list*
* *identifier* **:** *expression*

*nondeclarative_statement*:
## Nondeclarative Statements

*nondeclarative-statement*:
* *expression* **=** *expression*

*switch_block*:
* **{** *labeled_statement_list* **}**
*switch-block*:
* **{** *labeled-statement-list* **}**

*labeled_statement_list*:
* **case** number **:** *statement_list* *labeled_statement_list*
* **default** **:** *statement_list*
*labeled-statement-list*:
* **case** number **:** *statement-list* *labeled-statement-list*
* **default** **:** *statement-list*
* ε

## Expressions

*expression*:
* *expression* **?** *expression* **:** *expression*
* *expression* **||** *expression*
Expand Down Expand Up @@ -146,24 +173,27 @@
* *expression* **<<** *expression*
* *expression* **>>>** *expression*
* *expression* **>>** *expression*
* *expression* **..** *expression*
* *range*
* *expression* **.** *expression*
* *expression* **[** *expression* **]**
* **&** *expression*
* **|** *expression*
* **~** *expression*
* **[** *concatenation* **]**
* **mux** *expression* *mux_block*
* **$** *identifier* **(** *procedural_call* **)**
* **mux** *expression* *mux-block*
* **$** *identifier* **(** *procedural-call* **)**
* **(** *expression* **)**
* *identifier*
* *number*

*mux_block*:
* **{** *labeled_expression_list* **}**
*range*:
* *expression* **..** *expression*

*mux-block*:
* **{** *labeled-expression-list* **}**

*labeled_expression_list*:
* **case** *number* **:** *expression* **;** *labeled_expression_list*
*labeled-expression-list*:
* **case** *expression* **:** *expression* **;** *labeled-expression-list*
* **default** **:** *expression* **;**
* ε

Expand All @@ -173,17 +203,17 @@

*concatenatable*:
* *expression*
* *expression* **[[** expression **]]**
* *expression* **[[** *expression* **]]**

*procedural_call*:
* *procedural_call_list*
*procedural-call*:
* *procedural-call-list*
* ε

*procedural_call_list*:
* *expression* **,** *procedural_call_list*
*procedural-call-list*:
* *expression* **,** *procedural-call-list*
* *expression*

*array_subscript*:
*array-subscript*:
* **[** *expression* **]**
* ε

Expand Down
5 changes: 2 additions & 3 deletions Specifications/Readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# NOTE: None of these are guaranteed to be up to date.

I update these sporadically.
## Documentation
Up to date as of tag 0.0.2
2 changes: 1 addition & 1 deletion run_tests.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby

Dir["Examples/*"].map do |item|
Dir["Examples/*.phi"].map do |item|
puts "Testing #{item}..."
testable = item
testable += '/*' if File.directory?(item);
Expand Down

0 comments on commit b173430

Please sign in to comment.