Skip to content

Commit 480de90

Browse files
author
udhos
committed
Question mark as print.
1 parent 4040108 commit 480de90

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

basgo-build/build_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ var testTable = []buildTest{
115115
{"ugh", "", "", WRONG}, // invalid program
116116
{`10 print "ab"`, "", "ab\n", OK}, // minimum program
117117

118+
{`10 ? "?"`, "", "?\n", OK}, // print
119+
{`10 ? 1`, "", " 1 \n", OK}, // print
120+
{`10 ? 2.2`, "", " 2.2 \n", OK}, // print
121+
118122
{`10 print log(1);`, "", " 0 ", OK},
119123
{`10 print log(2.718281828459045);`, "", " 1 ", OK},
120124
{`10 print log(2.718281828459045^7);`, "", " 7 ", OK},

baslex/baslex.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const (
2828
TkErrInvalid = iota // Invalid, unexpected token found
2929
TkErrLarge = iota // Large token -- last error
3030

31+
TkQuestion = iota // Question ?
3132
TkHash = iota // Colon #
3233
TkColon = iota // Colon :
3334
TkComma = iota // Comma ,
@@ -323,6 +324,7 @@ var tabType = []string{
323324
"ERROR-INVALID",
324325
"ERROR-LARGE",
325326

327+
"QUESTION",
326328
"HASH",
327329
"COLON",
328330
"COMMA",

baslex/match.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ func matchBlank(l *Lex, b byte) Token {
263263
return l.saveLocationValue(Token{ID: TkPow, Value: "^"})
264264
case b == '\\':
265265
return l.saveLocationValue(Token{ID: TkBackSlash, Value: "\\"})
266+
case b == '?':
267+
return l.saveLocationValue(Token{ID: TkQuestion, Value: "?"})
266268
case b == '#':
267269
return l.saveLocationValue(Token{ID: TkHash, Value: "#"})
268270
case b == ':':

basparser/parser.y

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ import (
102102
%token <tok> TkErrInvalid
103103
%token <tok> TkErrLarge
104104

105+
%token <tok> TkQuestion
105106
%token <tok> TkHash
106107
%token <tok> TkColon
107108
%token <tok> TkComma
@@ -343,6 +344,8 @@ then_or_goto: TkKeywordThen
343344
| TkKeywordGoto
344345
;
345346

347+
print: TkKeywordPrint | TkQuestion ;
348+
346349
one_dim: TkIdentifier bracket_left const_list_num_noneg bracket_right
347350
{
348351
name := $1
@@ -692,7 +695,7 @@ stmt: /* empty */
692695
}
693696
$$ = &node.NodeClose{Numbers: list}
694697
}
695-
| TkKeywordPrint TkHash exp TkComma expressions_push printfile_expressions expressions_pop semicolon_optional
698+
| print TkHash exp TkComma expressions_push printfile_expressions expressions_pop semicolon_optional
696699
{
697700
num := $3
698701
list := $6
@@ -948,22 +951,22 @@ stmt: /* empty */
948951
Result.Baslib = true
949952
$$ = &node.NodeOpen{File:filename, Number:num, Mode:m}
950953
}
951-
| TkKeywordPrint
954+
| print
952955
{
953956
Result.Baslib = true
954957
$$ = &node.NodePrint{Newline: true}
955958
}
956-
| TkKeywordPrint expressions_push print_expressions expressions_pop
959+
| print expressions_push print_expressions expressions_pop
957960
{
958961
Result.Baslib = true
959962
$$ = &node.NodePrint{Expressions: $3, Newline: true}
960963
}
961-
| TkKeywordPrint expressions_push print_expressions TkSemicolon expressions_pop
964+
| print expressions_push print_expressions TkSemicolon expressions_pop
962965
{
963966
Result.Baslib = true
964967
$$ = &node.NodePrint{Expressions: $3}
965968
}
966-
| TkKeywordPrint expressions_push print_expressions TkComma expressions_pop
969+
| print expressions_push print_expressions TkComma expressions_pop
967970
{
968971
Result.Baslib = true
969972
$$ = &node.NodePrint{Expressions: $3, Tab: true}
@@ -1230,12 +1233,12 @@ stmt: /* empty */
12301233
$$ = &node.NodeScreen{Mode: mode}
12311234
}
12321235
| TkKeywordSound exp TkComma exp { $$ = unsupportedEmpty("SOUND") }
1233-
| TkKeywordView TkKeywordPrint
1236+
| TkKeywordView print
12341237
{
12351238
Result.Baslib = true
12361239
$$ = &node.NodeViewPrint{}
12371240
}
1238-
| TkKeywordView TkKeywordPrint exp TkKeywordTo exp
1241+
| TkKeywordView print exp TkKeywordTo exp
12391242
{
12401243
top := $3
12411244
bottom := $5

examples/question.bas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
10 ? "hello question mark print"

0 commit comments

Comments
 (0)