thesyncoder / jucc Goto Github PK
View Code? Open in Web Editor NEWJuCC - Jadavpur University Compiler Compiler
License: Apache License 2.0
JuCC - Jadavpur University Compiler Compiler
License: Apache License 2.0
Update header-safeguard in src/include/lexer/lexer.h
Header files follow the convention JUCC_LOCALNAMESPACE_FILENAME_H so we should update JUCC_LEXER_H to JUCC_LEXER_LEXER_H.
Add error detection in Parser and ParsingTable
We need to add more error statements in Parser class.
Add support in ParsingTable to detect grammar related errors like non ll(1) grammar.
Checklist
Make grammar and lexer consistent with problem statement.
Data Type : integer (int), floating point (float) and void
Declaration statements : identifiers are declared in declaration statements as basic data types and may also be assigned constant values (integer of floating)
Condition constructs: if, else, nested statements are supported. There may be if statement without else statement.
Assignments to the variables are performed using the input / output constructs:
cin >> x - Read into variable x
cout << x - Write variable x to output
Only arithmetic operators {+, -, *, %} and assignment operator `=โ are supported
Relational operators used in the if statement are < (less than), > (greater than), == (equal) and != (not equal)
Only function is main(), there is no other function. The main() function does not contain arguments and no return statements.
Rule for following operators should be present in grammar:
Support for additional tokens:
Update grammar.g file and lexer.
Add further documentation, specially in the main README.md file about the files in the project and what they do.
More details should be added instead of nothing yet.
Add error detection in parsing table for non - LL(1) grammars.
The parsing table shouldn't accept non-ambiguous grammar or grammar that is not LL(1).
A proper error message is recorded for ambiguous types of grammars.
Note: Before filing a bug report, please make sure to check whether the bug has already been filed. If it has, please do not re-file the report, our developers are already hard at work fixing it!
Segmentation fault on commented code
To address the bug, especially if it environment specific, we need to know what kind of configuration you are running on. Please include the following:
OS: Ubuntu (LTS) 20.04 or macOS 10.14+ (please specify version).
Compiler: GCC 7.0+ or Clang 8.0+.
CMake Profile: all
// comment
int main() {
;
}
ok
segmentation fault
OS: Ubuntu (LTS) 20.04 or macOS 10.14+ (please specify version).
Compiler: GCC 7.0+ or Clang 8.0+.
CMake Profile: all
## This is the grammar file for JuCC
## Edit this file to make changes to the parsing grammar
## Epsilon is represented by special string EPSILON
## Terminals
%terminals
else float if int void
( ) { } * + - / % ,
<< >> < > <= >= = == != ;
identifier integer_constant float_constant
main cin cout
%
## Non Terminals
%non_terminals
<primary_expression> <constant> <unary_operator> <unary_expression>
<type_specifier> <multiplicative_expression> <additive_expression>
<shift_expression> <relational_expression> <equality_expression>
<assignment_expression> <expression>
<declaration> <init_declarator_list> <init_declarator>
<initializer> <declarator> <direct_declarator>
<statement> <compound_statement> <block_item_list> <block_item>
<expression_statement> <selection_statement> <program>
%
## Start Symbol
%start
<program>
%
## Grammar for the language
%rules
## Expressions
<primary_expression> : identifier
<primary_expression> : <constant>
<primary_expression> : ( <expression> )
<constant> : integer_constant
<constant> : float_constant
<unary_operator> : +
<unary_operator> : -
<unary_expression> : <primary_expression>
<unary_expression> : <unary_operator> <primary_expression>
<multiplicative_expression> : <unary_expression>
<multiplicative_expression> : <multiplicative_expression> * <unary_expression>
<multiplicative_expression> : <multiplicative_expression> / <unary_expression>
<multiplicative_expression> : <multiplicative_expression> % <unary_expression>
<additive_expression> : <multiplicative_expression>
<additive_expression> : <additive_expression> + <multiplicative_expression>
<additive_expression> : <additive_expression> - <multiplicative_expression>
<shift_expression> : <additive_expression>
<shift_expression> : cin >> <additive_expression>
<shift_expression> : cout << <additive_expression>
<shift_expression> : <shift_expression> << <additive_expression>
<shift_expression> : <shift_expression> >> <additive_expression>
<relational_expression> : <shift_expression>
<relational_expression> : <relational_expression> < <shift_expression>
<relational_expression> : <relational_expression> > <shift_expression>
<relational_expression> : <relational_expression> <= <shift_expression>
<relational_expression> : <relational_expression> >= <shift_expression>
<equality_expression> : <relational_expression>
<equality_expression> : <equality_expression> == <relational_expression>
<equality_expression> : <equality_expression> != <relational_expression>
<assignment_expression> : <equality_expression>
<assignment_expression> : <assignment_expression> = <equality_expression>
<expression> : <assignment_expression>
## Declarations
<declaration> : <type_specifier> <init_declarator_list> ;
<init_declarator_list> : <init_declarator>
<init_declarator_list> : <init_declarator_list> , <init_declarator>
<init_declarator_list> : EPSILON
<init_declarator> : <declarator>
<init_declarator> : <declarator> = <initializer>
<type_specifier> : void
<type_specifier> : int
<type_specifier> : float
<declarator> : <direct_declarator>
<direct_declarator> : identifier
<direct_declarator> : ( <declarator> )
<initializer> : <assignment_expression>
## Statements
<statement> : <compound_statement>
<statement> : <expression_statement>
<statement> : <selection_statement>
<compound_statement> : { <block_item_list> }
<block_item_list> : <block_item>
<block_item_list> : <block_item> <block_item_list>
<block_item_list> : EPSILON
<block_item> : <declaration>
<block_item> : <statement>
<expression_statement> : <expression> ;
<expression_statement> : ;
<selection_statement> : if ( <expression> ) <compound_statement>
<selection_statement> : if ( <expression> ) <compound_statement> else <compound_statement>
## Main
<program> : <type_specifier> main ( ) <compound_statement>
%
int main() {
int x = 1 + 2 + 3 + 4;
if 1;
}
int
Some error ๐ข
Segmentation fault (core dumped)
The current implementation of the symbol tables deletes the lexemes on scope end and thus cannot be used for look-up after the lexer phase.
A better implementation would be an introduction of visibility flags - to be set to false on scope end rather than deleting.
Remove typedef Entity.
Entity is a string and Rule is a list of entities. Remove using Entity = std::vectorstd::string from grammar/grammer.h
Make other nessacary changes.
The lexer should be able to report the errors in parsing, and also report the line numbers of the input file associated with the same.
A proper structured error consisting of line number and column number ( if possible ) and the associated error message.
Currently, the CI is only running on ubuntu 20.04. However, JUCC has been tested on macOS with the required dependencies.
Maybe it's time to add a CI and put the project on a temporary hold ๐บ
Only bug fixes, no new feature for some time.
Update grammar to LL(1)
OS: Ubuntu (LTS) 20.04 or macOS 10.14+.
Compiler: GCC 7.0+ or Clang 8.0+.
CMake Profile: all
.
Known issue: with <assignment_expression>
productions.
in.cc:
int main() { if (a == 5) { ; } }
grammar.g: default
grammar is not ll(1). Firsts set for <assignment_expression>
productions intersect. There may be
more such issues.
Depends on #26.
Parser should successfully complete execution.
jucc: parsing table error: ...
Symbol Table bug
To address the bug, especially if it environment specific, we need to know what kind of configuration you are running on. Please include the following:
OS: Ubuntu (LTS) 20.04 or macOS 10.14+ (please specify version).
Compiler: GCC 7.0+ or Clang 8.0+.
CMake Profile: all
int main() {
int x, y;
cin >> x >> y;
if (x != 0) {
if (y > 0) {
cout << y;
} else {
cout << -y;
}
}
float z = 1 + 2 + 3 + 1000/ 50 * 23.2 * (x * y * 10);
// cout << x << y << z;
float z0 = 1 + 2 + 3 + 1000/ 50 * 23.2 * (x * y * 10);
float z1 = 1 + 2 - 3 + 1000/ 50 * 23.2 * (x * y * 10);
float z2 = 1 + 2 / 3 + 1000/ 50 * 23.2 * (x * y * 10);
float z3 = 1 + 2 * 3 + 1000/ 50 * 23.2 * (x * y * 10);
float z4 = 1 + 2 % 3 + 1000/ 50 * 23.2 * (x * y * 10);
float z5 = 1 + 2 > 3 + 1000/ 50 * 23.2 * (x * y * 10);
float z6 = 1 + 2 == 3 + 1000/ 50 * 23.2 * (x * y * 10);
float z7 = 1 + 2 != 3 + 1000/ 50 * 23.2 * (x * y * 10);
float z8 = 1 + 2 >= 3 + 1000/ 50 * 23.2 * (x * y * 10);
float z9 = 1 + 2 <= 3 + 1000/ 50 * 23.2 * (x * y * 10);
cout << z0 << z1 << z2 << z3 << z4;
cout << z5 << z6 << z7 << z8 << z9;
}
ok
jucc: duplicate symbol: x
duplicate symbol: y
duplicate symbol: x
duplicate symbol: y
duplicate symbol: x
duplicate symbol: y
duplicate symbol: x
duplicate symbol: y
duplicate symbol: x
duplicate symbol: y
duplicate symbol: x
duplicate symbol: y
duplicate symbol: x
duplicate symbol: y
duplicate symbol: x
duplicate symbol: y
duplicate symbol: x
duplicate symbol: y
duplicate symbol: x
duplicate symbol: y
duplicate symbol: x
duplicate symbol: y
No cout, cin terminals in current grammar, in src/grammar/grammar.g
The grammar should be able to support cout, cin and should have its respective rules.
for declarations like int x, y; y is detected as a undeclared symbol.
To address the bug, especially if it environment specific, we need to know what kind of configuration you are running on. Please include the following:
OS: Ubuntu (LTS) 20.04 or macOS 10.14+
Compiler: GCC 7.0+ or Clang 8.0+
CMake Profile: all
in.cc
int main() {
int x, y;
}
y is declared.
jucc: undelared symbol: y
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.