-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated v3x parser code (ParseHelper, ScannerAntlr, AST builder, erro…
…r listener). - src/CMakeLists.txt: - Added 'find_package(fmt 10.1.1)'. - Updated to a version of tree-gen that doesn't fetch fmt if the package is found. - v3x/cqasm-parse-helper: - Changed ScannerAntlr to have a customer error listener as a dependency injection. - Changed the 'parse' API to return a ParseResult. Ideally, a ParseResult should be an interface containing a pointer to a generic AST, not to a tree-gen AST. - v3x/BuildTreeGenAstVisitor: fixed so that all tests are now run. - v3x/CustomErrorListener: added so that the parser throws an exception instead of just printing to standard output. - res/v1x/toy-v1x-parsing: - All implemented tests pass the syntax analysis check. - Updated test_cases.txt. Note: - conanfile.py: temporarily commented out a few lines to be able to work with CLion's Conan Plugin. - test/CMakeLists.txt: temporarily commented out version tests. - test/v1x/parsing.cpp: temporarily commented out semantic checks.
- Loading branch information
Showing
86 changed files
with
1,076 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <antlr4-runtime.h> | ||
#include <exception> | ||
#include <string> | ||
|
||
|
||
namespace cqasm::v3x::parser { | ||
|
||
class CustomErrorListener : public antlr4::BaseErrorListener { | ||
/** | ||
* Name of the file being parsed. | ||
*/ | ||
std::string file_name_; | ||
private: | ||
void syntaxError(antlr4::Recognizer *recognizer, antlr4::Token *offendingSymbol, size_t line, | ||
size_t charPositionInLine, const std::string &msg, std::exception_ptr e) override; | ||
public: | ||
explicit CustomErrorListener(const std::string &file_name = "<unknown>") | ||
: file_name_{ file_name } {} | ||
}; | ||
|
||
} // namespace cqasm::v3x::parser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
res/v1x/toy-v1x-parsing/expression/out_of_bounds_index/ast.golden.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
SUCCESS | ||
Program( | ||
version: < | ||
Version( | ||
items: 3 | ||
) | ||
> | ||
num_qubits: < | ||
IntegerLiteral( | ||
value: 3 | ||
) | ||
> | ||
statements: < | ||
StatementList( | ||
items: [ | ||
Bundle( | ||
items: [ | ||
Instruction( | ||
name: < | ||
Identifier( | ||
name: x | ||
) | ||
> | ||
condition: - | ||
operands: < | ||
ExpressionList( | ||
items: [ | ||
IntegerLiteral( | ||
value: 1 | ||
) | ||
] | ||
) | ||
> | ||
annotations: [] | ||
) | ||
] | ||
annotations: [] | ||
) | ||
] | ||
) | ||
> | ||
) | ||
|
2 changes: 1 addition & 1 deletion
2
...parsing/expression/qubits_3__x_1/input.cq → ...g/expression/out_of_bounds_index/input.cq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
version 3 | ||
qubits 3 | ||
x 1 | ||
x q[3] |
Empty file.
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
Empty file.
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ERROR | ||
input.cq:5:11: extraneous input ',' expecting {INTEGER_LITERAL, FLOAT_LITERAL, IDENTIFIER} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ version 3 | |
qubits 3 | ||
h q[0] | ||
h q[1] | ||
cnot 123abc, q[0] | ||
cnot 123abc, q[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ERROR | ||
input.cq:5:17: mismatched input '<EOF>' expecting {INTEGER_LITERAL, FLOAT_LITERAL, IDENTIFIER} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ version 3 | |
qubits 3 | ||
h q[0] | ||
h q[1] | ||
cnot q[0], 123abc | ||
cnot q[0], 123abc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ERROR | ||
input.cq:5:10: mismatched input '<EOF>' expecting {INTEGER_LITERAL, FLOAT_LITERAL, IDENTIFIER} |
5 changes: 3 additions & 2 deletions
5
res/v1x/toy-v1x-parsing/expression_list/no_second_part/input.cq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
version 3 | ||
qubits 3 | ||
h q[0];h q[1] | ||
cnot q[0], | ||
h q[0] | ||
h q[1] | ||
cnot q[0], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
SUCCESS | ||
Program( | ||
version: < | ||
Version( | ||
items: 3 | ||
) | ||
> | ||
num_qubits: < | ||
IntegerLiteral( | ||
value: 3 | ||
) | ||
> | ||
statements: < | ||
StatementList( | ||
items: [ | ||
Bundle( | ||
items: [ | ||
Instruction( | ||
name: < | ||
Identifier( | ||
name: h | ||
) | ||
> | ||
condition: - | ||
operands: < | ||
ExpressionList( | ||
items: [ | ||
Index( | ||
expr: < | ||
Identifier( | ||
name: q | ||
) | ||
> | ||
indices: < | ||
IndexList( | ||
items: [ | ||
IndexItem( | ||
index: < | ||
IntegerLiteral( | ||
value: 0 | ||
) | ||
> | ||
) | ||
] | ||
) | ||
> | ||
) | ||
] | ||
) | ||
> | ||
annotations: [] | ||
) | ||
] | ||
annotations: [] | ||
) | ||
Bundle( | ||
items: [ | ||
Instruction( | ||
name: < | ||
Identifier( | ||
name: h | ||
) | ||
> | ||
condition: - | ||
operands: < | ||
ExpressionList( | ||
items: [ | ||
Index( | ||
expr: < | ||
Identifier( | ||
name: q | ||
) | ||
> | ||
indices: < | ||
IndexList( | ||
items: [ | ||
IndexItem( | ||
index: < | ||
IntegerLiteral( | ||
value: 1 | ||
) | ||
> | ||
) | ||
] | ||
) | ||
> | ||
) | ||
] | ||
) | ||
> | ||
annotations: [] | ||
) | ||
] | ||
annotations: [] | ||
) | ||
Bundle( | ||
items: [ | ||
Instruction( | ||
name: < | ||
Identifier( | ||
name: cnot | ||
) | ||
> | ||
condition: - | ||
operands: < | ||
ExpressionList( | ||
items: [ | ||
Index( | ||
expr: < | ||
Identifier( | ||
name: q | ||
) | ||
> | ||
indices: < | ||
IndexList( | ||
items: [ | ||
IndexItem( | ||
index: < | ||
IntegerLiteral( | ||
value: 0 | ||
) | ||
> | ||
) | ||
] | ||
) | ||
> | ||
) | ||
Index( | ||
expr: < | ||
Identifier( | ||
name: q | ||
) | ||
> | ||
indices: < | ||
IndexList( | ||
items: [ | ||
IndexItem( | ||
index: < | ||
IntegerLiteral( | ||
value: 1 | ||
) | ||
> | ||
) | ||
] | ||
) | ||
> | ||
) | ||
] | ||
) | ||
> | ||
annotations: [] | ||
) | ||
] | ||
annotations: [] | ||
) | ||
] | ||
) | ||
> | ||
) | ||
|
Oops, something went wrong.