Skip to content
This repository has been archived by the owner on Nov 17, 2022. It is now read-only.

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Zouev committed Apr 18, 2022
1 parent 37106da commit 3277fde
Show file tree
Hide file tree
Showing 105 changed files with 17,459 additions and 2,506 deletions.
154 changes: 138 additions & 16 deletions src/main/java/lexer/Scanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public int yylex() {
lastToken = get();

if (Entity.debug) {
System.out.print(lastToken.span.getBegin().getLine());
System.out.print(" ");
System.out.print(lastToken.code);
if (lastToken.code == TokenCode.Identifier) {
System.out.print(" " + lastToken.image);
Expand All @@ -77,13 +79,18 @@ public Token getLVal() {
return lastToken;
}

int lineNum = 1;
int posNum = 1;

@Override
public void yyerror(String msg) {
System.err.println(msg);
System.out.print(lineNum);
System.out.print(" ");
System.out.println(msg);
}

public Token get() {
// if ( currentToken == null ) currentToken = getToken();
// if ( currentToken == null ) currentToken = getToken();

while (true) {
currentToken = getToken();
Expand All @@ -107,30 +114,33 @@ private Token getToken() {
String image;
Token token;

// if ( Entity.inBlock && Entity.unAnnotatedTypeTaken )
// {
// Entity.unAnnotatedTypeTaken = false;
// return new Token(TokenCode.Phantom,"");
// }
// if ( Entity.inBlock && Entity.unAnnotatedTypeTaken )
// {
// Entity.unAnnotatedTypeTaken = false;
// return new Token(TokenCode.Phantom,"");
// }

while (true) {
ch = getChar();
if (ch == charZero) {
return new Token(TokenCode.EOS, "");
Token end = new Token(TokenCode.EOS, "");
end.setSpan(new Span(new Pos(lineNum,posNum),null));
return end;
}
if (ch == ' ' || ch == '\t') {
// currentPos++;
// currentPos++;
forgetChar();
continue;
}
if (ch == '\n') {
// currentLine++;
// currentPos = 0;
lineNum++;
// currentLine++;
// currentPos = 0;
forgetChar();
continue;
}
if (ch == '\r') {
// currentPos = 0;
// currentPos = 0;
forgetChar();
continue;
}
Expand Down Expand Up @@ -491,6 +501,88 @@ private Token getToken() {
}
break;

case '0': // integer
String literal = "" + ch;
forgetChar();
ch = getChar();
switch ( ch ) {
case 'x':
case 'X':
forgetChar();
literal += ch;
while (true) {
ch = getChar();
if (isHexadecimal(ch)) {
literal += ch;
forgetChar();
} else if (ch == '_') {
forgetChar();
continue;
} else
break;
}
break;

case 'o':
case 'O':
forgetChar();
literal += ch;
while (true) {
ch = getChar();
if (isOctal(ch)) {
literal += ch;
forgetChar();
} else if (ch == '_') {
forgetChar();
continue;
} else
break;
}
break;

case 'b':
case 'B':
forgetChar();
literal += ch;
while (true) {
ch = getChar();
if (isBinary(ch)) {
literal += ch;
forgetChar();
} else if (ch == '_') {
forgetChar();
continue;
} else
break;
}
break;

default:
while (true) {
if (Character.isDigit(ch)) {
literal = literal.concat("" + ch);
forgetChar();
ch = getChar();
} else if (ch == '_') {
forgetChar();
ch = getChar();
continue;
} else {
// forgetChar();
break;
}
}
break;
}
if ( Character.toUpperCase(ch) == 'L' )
{
literal += "" + ch;
forgetChar();
}
image = literal;
code = TokenCode.IntegerLiteral;
break;

default:
if (Character.isJavaIdentifierStart(ch)) {
String identifier = "" + ch;
Expand All @@ -507,12 +599,14 @@ private Token getToken() {
image = identifier;
code = detectKeyword(identifier);
} else if (Character.isDigit(ch)) {
String literal = "" + ch;
literal = "" + ch;
while (true) {
forgetChar();
ch = getChar();
if (Character.isDigit(ch)) {
literal = literal.concat("" + ch);
} else if ( ch == '_' ) {
continue;
} else {
// forgetChar();
break;
Expand All @@ -526,8 +620,13 @@ private Token getToken() {
while (true) {
if (Character.isDigit(ch)) {
literal = literal.concat("" + ch);
} else {
forgetChar();
ch = getChar();
continue;
} else if ( ch == '_' ) {
continue;
} else {
//forgetChar();
break;
}
}
Expand All @@ -543,15 +642,35 @@ private Token getToken() {
break;
}
token = new Token(code, image);
token.setSpan(new Span(new Pos(lineNum,posNum),null));
return token;
}

private boolean isHexadecimal(char ch)
{
if ( Character.isDigit(ch) ) return true;
char chU = Character.toUpperCase(ch);
if ( chU >= 'A' && chU <= 'F' ) return true;
return false;
}

private boolean isOctal(char ch)
{
return (ch>='0' && ch<='7');
}

private boolean isBinary(char ch)
{
return ch == '0' || ch == '1';
}

private String scanShortComment() {
StringBuilder comment = new StringBuilder();
while (true) {
char ch = getChar();
forgetChar();
if (ch == '\n') {
lineNum++;
break;
}
comment.append(ch);
Expand All @@ -573,6 +692,9 @@ private String scanLongComment() {
} else {
comment.append("*").append(ch);
}
} else if (ch == '\n') {
lineNum++;
comment.append(ch);
} else {
comment.append(ch);
}
Expand All @@ -591,7 +713,7 @@ private TokenCode detectKeyword(String identifier) {
case "case" -> TokenCode.Case;
case "char" -> TokenCode.Char;
case "class" -> TokenCode.Class;
// case "const" : return TokenCode.Const; // not actually used
// case "const" -> TokenCode.Const; // not actually used
case "continue" -> TokenCode.Continue;
case "default" -> TokenCode.Default;
case "do" -> TokenCode.Do;
Expand All @@ -603,7 +725,7 @@ private TokenCode detectKeyword(String identifier) {
case "finally" -> TokenCode.Finally;
case "float" -> TokenCode.Float;
case "for" -> TokenCode.For;
// case "goto" : return TokenCode.Goto; // not actually used
// case "goto" -> TokenCode.Goto; // not actually used
case "if" -> TokenCode.If;
case "implements" -> TokenCode.Implements;
case "import" -> TokenCode.Import;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/lexer/TokenCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public enum TokenCode {
// to be distinguished from a yield statement. record has special meaning
// in a record declaration (§8.10).

True(Lexer.FALSE),
True(Lexer.TRUE),
False(Lexer.FALSE),
Null(Lexer.NULL),

Expand Down
Loading

1 comment on commit 3277fde

@0pdd
Copy link
Member

@0pdd 0pdd commented on 3277fde Apr 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to retrieve PDD puzzles from the code base and submit them to GitHub. If you think that it's a bug on our side, please submit it to yegor256/0pdd:

set -x && set -e && set -o pipefail && cd /tmp/0pdd20220303-12-17lwdzx/polystat/j2ast && pdd -v -f /tmp/20220418-25833-kq4vq0 [1]: + set -e + set -o pipefail + cd /tmp/0pdd20220303-12-17lwdzx/polystat/j2ast + pdd -v -f /tmp/20220418-25833-kq4vq0 My version is 0.20.6 Ruby version is 2.6.0 at...

Please, copy and paste this stack trace to GitHub:

UserError
set -x && set -e && set -o pipefail && cd /tmp/0pdd20220303-12-17lwdzx/polystat/j2ast && pdd -v -f /tmp/20220418-25833-kq4vq0 [1]:
+ set -e
+ set -o pipefail
+ cd /tmp/0pdd20220303-12-17lwdzx/polystat/j2ast
+ pdd -v -f /tmp/20220418-25833-kq4vq0

My version is 0.20.6
Ruby version is 2.6.0 at x86_64-linux
Reading /tmp/0pdd20220303-12-17lwdzx/polystat/j2ast
278 file(s) found, 58 excluded
/tmp/0pdd20220303-12-17lwdzx/polystat/j2ast/bin/custom_build_rules/docs/Verbosity.png is a binary file (29722 bytes)
/tmp/0pdd20220303-12-17lwdzx/polystat/j2ast/bin/custom_build_rules/docs/FlexProperties.png is a binary file (26767 bytes)
/tmp/0pdd20220303-12-17lwdzx/polystat/j2ast/bin/custom_build_rules/docs/3.png is a binary file (7316 bytes)
/tmp/0pdd20220303-12-17lwdzx/polystat/j2ast/bin/custom_build_rules/docs/6.png is a binary file (15611 bytes)
/tmp/0pdd20220303-12-17lwdzx/polystat/j2ast/bin/custom_build_rules/docs/BisonProperties.png is a binary file (27186 bytes)
/tmp/0pdd20220303-12-17lwdzx/polystat/j2ast/bin/custom_build_rules/docs/2.png is a binary file (11445 bytes)
/tmp/0pdd20220303-12-17lwdzx/polystat/j2ast/bin/custom_build_rules/docs/Flex_debuging.png is a binary file (27219 bytes)
/tmp/0pdd20220303-12-17lwdzx/polystat/j2ast/bin/custom_build_rules/docs/Properties.png is a binary file (31446 bytes)
/tmp/0pdd20220303-12-17lwdzx/polystat/j2ast/bin/custom_build_rules/docs/4.png is a binary file (12213 bytes)
/tmp/0pdd20220303-12-17lwdzx/polystat/j2ast/bin/custom_build_rules/docs/1.png is a binary file (31654 bytes)
/tmp/0pdd20220303-12-17lwdzx/polystat/j2ast/bin/custom_build_rules/docs/5.png is a binary file (11534 bytes)
/tmp/0pdd20220303-12-17lwdzx/polystat/j2ast/bin/win_bison.exe is a binary file (665600 bytes)
/tmp/0pdd20220303-12-17lwdzx/polystat/j2ast/bin/win_flex.exe is a binary file (569344 bytes)
/tmp/0pdd20220303-12-17lwdzx/polystat/j2ast/bin/bison_mac is a binary file (487680 bytes)
/tmp/0pdd20220303-12-17lwdzx/polystat/j2ast/gradle/wrapper/gradle-wrapper.jar is a binary file (59821 bytes)
Reading bin/README.md...
Reading bin/changelog.md...
Reading bin/custom_build_rules/README.md...
Reading bin/custom_build_rules/win_flex_only/win_flex_custom_build.targets...
Reading bin/custom_build_rules/win_flex_only/win_flex_custom_build.props...
Reading bin/custom_build_rules/win_flex_only/win_flex_custom_build.xml...
Reading bin/custom_build_rules/win_bison_only/win_bison_custom_build.xml...
Reading bin/custom_build_rules/win_bison_only/win_bison_custom_build.props...
Reading bin/custom_build_rules/win_bison_only/win_bison_custom_build.targets...
Reading bin/custom_build_rules/win_flex_bison/win_flex_bison_custom_build.props...
Reading bin/custom_build_rules/win_flex_bison/win_flex_bison_custom_build.targets...
Reading bin/custom_build_rules/win_flex_bison/win_flex_bison_custom_build.xml...
Reading bin/data/local.mk...
Reading bin/data/README.md...
Reading bin/data/bison-default.css...
Reading bin/data/m4sugar/m4sugar.m4...
Reading bin/data/m4sugar/foreach.m4...
Reading bin/data/skeletons/java-skel.m4...
Reading bin/data/skeletons/location.cc...
Reading bin/data/skeletons/lalr1.java...
Reading bin/data/skeletons/c++.m4...
Reading bin/data/skeletons/traceon.m4...
Reading bin/data/skeletons/glr.cc...
Reading bin/data/skeletons/glr.c...
Reading bin/data/skeletons/c++-skel.m4...
Reading bin/data/skeletons/d.m4...
ERROR: bin/data/skeletons/d.m4; puzzle at line #298; TODO found, but puzzle can't be parsed, most probably because TODO is not followed by a puzzle marker, as this page explains: https://github.com/yegor256/pdd#how-to-format
If you can't understand the cause of this issue or you don't know how to fix it, please submit a GitHub issue, we will try to help you: https://github.com/yegor256/pdd/issues. This tool is still in its beta version and we will appreciate your feedback. Here is where you can find more documentation: https://github.com/yegor256/pdd/blob/master/README.md.
Exit code is 1

/app/objects/git_repo.rb:66:in `rescue in block in xml'
/app/objects/git_repo.rb:63:in `block in xml'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/tempfile.rb:295:in `open'
/app/objects/git_repo.rb:62:in `xml'
/app/objects/puzzles.rb:36:in `deploy'
/app/objects/job.rb:38:in `proceed'
/app/objects/job_starred.rb:33:in `proceed'
/app/objects/job_recorded.rb:32:in `proceed'
/app/objects/job_emailed.rb:35:in `proceed'
/app/objects/job_commiterrors.rb:36:in `proceed'
/app/objects/job_detached.rb:48:in `exclusive'
/app/objects/job_detached.rb:36:in `block in proceed'
/app/objects/job_detached.rb:36:in `fork'
/app/objects/job_detached.rb:36:in `proceed'
/app/0pdd.rb:366:in `block in <top (required)>'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1675:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1675:in `block in compile!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1013:in `block (3 levels) in route!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1032:in `route_eval'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1013:in `block (2 levels) in route!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1061:in `block in process_route'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1059:in `catch'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1059:in `process_route'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1011:in `block in route!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1008:in `each'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1008:in `route!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1129:in `block in dispatch!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1101:in `block in invoke'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1101:in `catch'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1101:in `invoke'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1124:in `dispatch!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:939:in `block in call!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1101:in `block in invoke'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1101:in `catch'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1101:in `invoke'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:939:in `call!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:929:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.1.0/lib/rack/protection/xss_header.rb:18:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.1.0/lib/rack/protection/path_traversal.rb:16:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.1.0/lib/rack/protection/json_csrf.rb:26:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.1.0/lib/rack/protection/base.rb:50:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.1.0/lib/rack/protection/base.rb:50:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.1.0/lib/rack/protection/frame_options.rb:31:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.2.3/lib/rack/logger.rb:17:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.2.3/lib/rack/common_logger.rb:38:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:253:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:246:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.2.3/lib/rack/head.rb:12:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.2.3/lib/rack/method_override.rb:24:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:216:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1991:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1542:in `block in call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1769:in `synchronize'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:1542:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.2.3/lib/rack/handler/webrick.rb:95:in `service'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/webrick/httpserver.rb:140:in `service'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/webrick/httpserver.rb:96:in `run'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/webrick/server.rb:307:in `block in start_thread'

Please sign in to comment.